package edu.nf.db.util.result;

import edu.nf.db.util.ResultSetHandler;
import edu.nf.db.util.RowProcessor;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author lzp
 * @Date 2024-05-08
 */
public class BeanHandler<T> implements ResultSetHandler<T> {

    private final Class<T> beanClass;

    public BeanHandler(Class<T> beanClass) {
        this.beanClass = beanClass;
    }

    @Override
    public T handle(ResultSet rs) throws SQLException {
        try {
            return rs.next()? RowProcessor.toBean(rs,beanClass):null;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
